<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="../css/document/BeAlert.css">
    <link rel="stylesheet" type="text/css" href="../css/document/gth-cate.css">
    <script type="text/javascript" src="../js/jquery-3.6.0.js"></script>
    <script src="https://layui.org.cn/res/layui/release/layer/dist/layer.js-v=351-1.js"></script>
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/document/BeAlert.js"></script>
    <script type="text/javascript" src="../js/document/gth-cate.js"></script>
    <style>
        table tr th {
            border: 1px solid #e6e6e6;
            background-color: white
        }

        table tr td {
            border: 1px solid #e6e6e6;
            background-color: white
        }
    </style>
</head>
<body>
<div>
    <inpput type="hidden" style="color: white;display: inline;" th:text="${selall.pages}" class="pages"></inpput>
    <inpput type="hidden" style="color: white;display: inline;" th:text="${selall.pageNum}" class="PageNum">
    </inpput>

    <!--第一个表格-->
    <table class="layui_table" style="width: 97%; margin:0px auto" border="1">
        <tr align="center" height="60">
            <td>文件类型：</td>
            <td width="20%"><select class="filetype"
                                    style="height: 35px; width: 95%; background-color: white; border: 1px solid #e6e6e6">
                <option value="">请选择</option>
                <option value="1">文件夹</option>
                <option value="2">Word文件</option>
                <option value="4">图片</option>
                <option value="3">记事本</option>
                <option value="5">pdf文件</option>
                <option value="6">xls文件</option>
                <option value="7">压缩文件</option>
            </select>
            </td>
            <td>文件名：</td>
            <td width="20%"><input type="text" class="layui-input cname" style="width: 95%"></td>
            <td>创建日期：</td>
            <td align="center" width="20%"><input type="text" class="layui-input createDate" id="test1"
                                                  style="width: 95%"></td>
            <td align="center"><input type="button" onclick="examine()" style="margin-left: 20px" id="alert"
                                      data-method="confirmTrans" class="layui-btn" value="检索">
        </tr>

        <tr style="height: 80px;">
            <td colspan="7">
                <h2>&nbsp;&nbsp;&nbsp;文档列表</h2>
                <input type="image" src="../images/document/jia.png" onclick="addfolder()" class="wenjianjia"><span
                    class="wenzi">添加文件夹</span>
                <input type="image" src="../images/document/tiantxt.png" onclick="addfiles()" class="wenjian"><span
                    class="wenzi2">添加文件</span>
                <input type="button" class="layui-btn layui-btn-warm"
                       style="height: 30px;line-height: 30px; float: right; margin-right: -380px;margin-top: -28px;border-radius:5%;"
                       onclick="echarts()" value="文件可视化">
            </td>
        </tr>
    </table>
    <!--第二个表格-->
    <table class="layui_table table-page" id="sss" style="width: 97%; margin:0px auto;">
        <thead>
        <tr height="50">
            <th>序号</th>
            <th colspan="2">名称</th>
            <th style="width: 60px;">类型</th>
            <th colspan="1">所在部门</th>
            <th style="width: 250px;">创建时间</th>
            <th>操作</th>
            <br>
        </tr>
        </thead>
        <tbody class="maininfo">
        <tr th:each="cate:${selall.list}" height="50">
            <input type="hidden" th:value="${cate.getId()}" class="aid">
            <input type="hidden" th:value="${session.user.getId()}" class="uid">
            <input type="hidden" th:value="${cate.getDp_id()}" class="dp_id">
            <td align="center"></td>
            <span th:if="${cate.getType()==1}">
                <td colspan="2" class="place cname" th:text="${cate.getTitle()}"
                    th:onclick="'javascript:orderby(\''+${cate.getId()}+'\')'"></td>
            </span>
            <td th:if="${cate.getType()!=1}" colspan="2" class="place cname" th:text="${cate.getTitle()}">
            <td align="center" th:if="${cate.getType()}==1"><img src="../images/document/jia2.png"></td>
            <td   style="height: 60px!important;"  align="center" th:if="${cate.getType()}==2"><img src="../images/document/doc.png"></td>
            <td   style="height: 60px!important;"  align="center" th:if="${cate.getType()}==3"><img src="../images/document/txt.png"></td>
            <td   style="height: 60px!important;"  align="center" th:if="${cate.getType()}==4"><img src="../images/document/jpg.png"></td>
            <td   style="height: 60px!important;"  align="center" th:if="${cate.getType()}==5"><img src="../images/document/pdf.png"></td>
            <td   style="height: 60px!important;"  align="center" th:if="${cate.getType()}==6"><img src="../images/document/xls.png"></td>
            <td   style="height: 60px!important;"  align="center" th:if="${cate.getType()}==7"><img src="../images/document/zip.png"></td>
            <td width="100" class="place" th:text="${cate.getDepartment().getDepartmentname()}"></td>
            <td width="150" class="place createDate"
                th:text="${#dates.format(cate.getCreateDate(),'yyyy-MM-dd HH:mm:ss')}"></td>
            <td class="place" width="350"><input type="button"
                                                 style=" height: 30px;line-height: 30px;margin-left: 15px;"
                                                 class="layui-btn  layui-btn-normal"
                                                 id="test2"
                                                 th:onclick="'javascript:lookupdate(\''+${cate.getId()}+'\')'"
                                                 value="修改"> <input type="button"
                                                                    style="height: 30px;line-height: 30px;"
                                                                    class="layui-btn layui-btn-danger"
                                                                    th:onclick="'javascript:reupdate(\''+${cate.getId()}+'\')'"
                                                                    value="删除">
                <span style="margin-left: 10px" th:if="${cate.getType() != 1}"><input type="button"
                                                                                      style="height: 30px;line-height: 30px;"
                                                                                      class="layui-btn  layui-btn-normal"
                                                                                      th:onclick="down([[${cate.getNewfilename()}]])"
                                                                                      value="下载"></span>
                <!--           <span style="margin-left: 10px" th:if="${cate.getType() != 1}"><button style="height: 30px;line-height: 30px;" class="layui-btn"><a style="color: white" th:href="@{/document/download(id=${cate.getId()}, openStyle='inline')}">查看</a></button></span>-->
                <span style="margin-left: 10px" th:if="${cate.getType() != 1}"><button
                        style="height: 30px;line-height: 30px;" class="layui-btn"
                        th:onclick="che([[${cate.getPath()}]])">查看</button></span>
            </td>
        </tr>
        </tbody>
    </table>
    <div style="text-align: center;margin-top: 20px; margin-bottom: 20px">
        <a href="javascript:void(0)" type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-bg-green"
           onclick="start()">首页</a>
        <a type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-bg-green " href="javascript:void(0)"
           onclick="prev()">
            <i class="layui-icon layui-icon-left "></i></a>
        <a class="layui-btn layui-btn-sm layui-btn-primary ">
            <span><b class="yeshu"> / </b></span></a>
        <a type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-bg-green" href="javascript:void(0)"
           onclick="next()">
            <i class="layui-icon layui-icon-right "></i>
        </a>
        <a href="javascript:void(0)" type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-bg-green"
           onclick="end()">尾页</a>
    </div>

    <!--websocket-->
    <input type="hidden" th:value="${session.user.getId()}" id="u_id">
</div>
</body>
<script>
    var pages = $(".pages").text();
    var pageNum = $(".PageNum").text();
    console.log("总页数：------------------------" + pages)
    console.log("当前页：--------------------------" + pageNum)

    var currentPage = parseInt(pageNum);
    var pageSize = 5;
    var sumPage = parseInt(pages);
    if (sumPage == 0) {
        sumPage = 1
    }
    $(".yeshu").text("第" + currentPage + "页 / 共" + sumPage + "页")

    function showPage() {
        location.href = "/document/listdocument?currentPage=" + currentPage + "&pageSize=" + pageSize
    }

    function next() {
        currentPage = currentPage + 1;
        console.log(currentPage + "----------currentPage")
        if (currentPage > sumPage) {
            currentPage = sumPage;
            layer.msg("最后一页啦")
            return;
        }
        showPage();
    }

    function prev() {
        currentPage = currentPage - 1;
        if (currentPage < 1) {
            currentPage = 1;
            layer.msg("前面没有啦")
            return;
        }
        showPage();
    }

    function end() {
        currentPage = sumPage
        showPage();

    }

    function start() {
        currentPage = 1
        showPage();

    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#test1'
        });
    });
</script>
</html>

<!--websocket-->
<script type="text/javascript">
    $(function () {
        var urlPrefix = 'ws://127.0.0.1:8081/ws/';
        var ws = null;
        var joinfun = function () {
            var userId = $("#u_id").val();
            var url = urlPrefix + userId;
            console.log(url + "----------------")
            ws = new WebSocket(url);
            ws.onopen = function () {
                console.log("建立 websocket 连接...");
            };
            ws.onmessage = function (event) {
                let aaa = JSON.parse(event.data);

                alert(aaa.content);

            };
            ws.onclose = function () {
                console.log("关闭 websocket 连接...");
            }
        };
        joinfun();//自动连接
    });
</script>
